//
//  AppConst.m
//  PeiJue
//
//  Created by 李西亚 on 2017/9/20.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import "AppConst.h"

///*******    通知    ********///
/** 选中相册时通知控制器刷新界面 */
NSString * const kSelectedAlbumChangedNotification = @"kSelectedAlbumChangedNotification";


///*******    登录相关    ********///






///*******      其他    ********///






///*******    HOST    ********///
static NSString *kApiServerURL = @"apiServerURL";
static NSString *kWebHtmlServerURL = @"webServerURL";

static NSString *kChannelInhouse = @"inHouse";
static NSString *kChannelAppSotre = @"appStore";
static NSString *kAppStoreBundleIdentifier = @"";
static NSString *kInHouseBundleIdentifier  = @"";

@implementation AppConst
+ (instancetype)sharedInstance{
    static AppConst *appConst = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        appConst = [[AppConst alloc] init];
    });
    return appConst;
}

#pragma mark - Privates
- (NSString *)readValueFromConfigurationFileForKey:(NSString *)key{
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"Environments" ofType:@"plist"];
    NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:path];
    NSString *currentConfigKey = nil;
    
#ifdef DEBUG
    currentConfigKey = @"Debug";
#elif RELEASE
    currentConfigKey = @"Release";
#elif TDEBUG
    currentConfigKey = @"TDebug";
#elif TRELEASE
    currentConfigKey = @"TRelease";
#endif
    
    NSLog( @"环境: %@",currentConfigKey);
    NSDictionary *currConfDic = config[currentConfigKey];
    return currConfDic[key];
}

#pragma mark - Publics
- (NSString *)apiHost{
    return [self readValueFromConfigurationFileForKey:kApiServerURL];
}

- (NSString *)webHtmlHost{
    return [self readValueFromConfigurationFileForKey:kWebHtmlServerURL];
}

- (NSString *)channelName{
    NSString *channelName = kChannelInhouse;
    NSString *bundleId = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey];
    if ([bundleId isEqualToString:kAppStoreBundleIdentifier]) {
        channelName = kChannelAppSotre;
    }
    return channelName;
}
@end
